﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics.Contracts;

namespace DesignByContract.CodeContracts
{
    public class CEL
    {
        private double _minimum = 1;
        public string ContractID { get; private set; }

        public CEL(string contractID)
        {
            ContractID = contractID;
        }

        [ContractInvariantMethod]
        private void ContractInvariants()
        {
            Contract.Invariant(_minimum >= 1);
            Contract.Invariant(ContractID.Length == 4);
        }

        public virtual double ComputeInterest(double amount, double rate)
        {
            //Pre-Condition
            Contract.Requires(rate < 1, "Interest rate must be less than 1.");

            //Post-Condition
            Contract.Ensures(Contract.Result<double>() > amount, "Amount after interest must be superior to initial amount.");

            return amount + amount * rate + _minimum;
        }

        public virtual double ComputeInterest(double amount, double rate, double minimum)
        {
            _minimum = minimum;
            return ComputeInterest(amount, rate);
        }
    }
}
